package com.sanjiahantang.youjiarole.module.common.holders;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.module.common.beans.HomeBean;
import com.sanjiahantang.youjiarole.module.common.views.impl.WebActivity;
import com.sanjiahantang.youjiarole.utils.BannerImageLoader;
import com.sanjiahantang.youjiarole.utils.FileUtils;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/8.
 */

public class BannerHolder extends RecyclerView.ViewHolder {

    private Banner banner;
    private List<String> urls;

    public BannerHolder(View itemView, final Context context, final List<HomeBean.Advertise> datas) {
        super(itemView);
        urls = new ArrayList<>();
        for (HomeBean.Advertise ad : datas) {
            urls.add(FileUtils.rePath(ad.getUrl()));
        }
        banner = (Banner) itemView.findViewById(R.id.home_banner);
        banner.setImageLoader(new BannerImageLoader());
        banner.setImages(urls);
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        banner.setIndicatorGravity(BannerConfig.RIGHT);
        banner.setBannerAnimation(Transformer.ZoomOutSlide);
        banner.setDelayTime(2000);
        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                Intent intent=new Intent(context,WebActivity.class);
                intent.putExtra("url",datas.get(position).getLinkLocation());
                context.startActivity(intent);
            }
        });

        banner.start();

    }

}
